#include "Crosshair.h"

Crosshair g_pCrosshair;

void Crosshair::Init()
{
	Active = true;
	Size = 14;
	Width = 1;
	SetColor(0x00FF0000FF);
}

void Crosshair::Enable()
{
	Active = true;
}

void Crosshair::Disable()
{
	Active = false;
}

void Crosshair::Set( bool Active )
{
	this->Active = Active;
}

void Crosshair::SetSize( int Size )
{
	this->Size = Size;
}

void Crosshair::SetWidth( int Width )
{
	this->Width = Width;
}

void Crosshair::SetColor(DWORD dwColor)
{
	DrawColor = dwColor;
}

void Crosshair::Draw()
{
	if (Active)
	{
		int ScreenW;
		int ScreenH;
		g_pInterfaces.g_pEngine->GetScreenSize(&ScreenW, &ScreenH);
		ScreenH /= 2;
		ScreenW /= 2;
		
		if(g_pEventManager.hitplayer)
		{
			time = GetTickCount();
			g_pEventManager.hitplayer = false;
		}

		if(time)
		{
			int delta = GetTickCount() - time;

			if(delta <= 500)
			{
				GRender.CornerBox(ScreenW - 10, ScreenH - 10, 5, 15, 20, 255, 255, 255, 255);
			}
			else
			{
				time = -1;
			}
		}

		GRender.FillRGBA(ScreenW - Size, ScreenH - Width, Size*2, Width*2,(DrawColor>>16)&0xFF, (DrawColor>>8)&0xFF, (DrawColor>>0)&0xFF, (DrawColor>>24)&0xFF); // --
		GRender.FillRGBA(ScreenW - Width, ScreenH - Size, Width*2, Size*2,(DrawColor>>16)&0xFF, (DrawColor>>8)&0xFF, (DrawColor>>0)&0xFF, (DrawColor>>24)&0xFF); //  |
		GRender.FillRGBA(ScreenW - Width, ScreenH - Size, Size + Width*2, Width*2,(DrawColor>>16)&0xFF, (DrawColor>>8)&0xFF, (DrawColor>>0)&0xFF, (DrawColor>>24)&0xFF); // ^
		GRender.FillRGBA(ScreenW - Size, ScreenH + Size - Width, Size + Width, Width*2,(DrawColor>>16)&0xFF, (DrawColor>>8)&0xFF, (DrawColor>>0)&0xFF, (DrawColor>>24)&0xFF); // _
		GRender.FillRGBA(ScreenW + Size - Width, ScreenH - Width, Width*2, Size+Width*2,(DrawColor>>16)&0xFF, (DrawColor>>8)&0xFF, (DrawColor>>0)&0xFF, (DrawColor>>24)&0xFF); // q
		GRender.FillRGBA(ScreenW - Size, ScreenH - Size, Width*2, Size,(DrawColor>>16)&0xFF, (DrawColor>>8)&0xFF, (DrawColor>>0)&0xFF, (DrawColor>>24)&0xFF); // p
	}
}
